<%@ page import="com.jack.bookshop.vo.UserVo" %>
<%@ page import="com.jack.bookshop.vo.OrderVo" %>
<%@ page import="java.util.List" %>
<%@ page import="com.jack.bookshop.vo.OrderBookVo" %>
<%@ page language="java" contentType="text/html;charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<%
    UserVo userVo = (UserVo) session.getAttribute("userVo");
    List<OrderBookVo> list = (List<OrderBookVo>) session.getAttribute("bookorder");
//  System.out.println(list);
//  List<OrderVo> list = (List<OrderVo>) session.getAttribute("orderlist");
    pageContext.setAttribute("list", list);
%>
<!DOCTYPE html>
<html>
<head>
    <title>Jack's Bookshop</title>
    <!-- 导入资源 -->
    <%@ include file="resource.jsp" %>
    <!-- Javascript代码放这里 -->
    <script>
        window.onload = function () {
            let total = document.getElementById("price");
            total.value = parseFloat(total.value).toFixed(2);
        }
    </script>
</head>
<body>
<!-- 导入页头 -->
<%@ include file="header.jsp" %>
<%
    double total = 0;
    for (int i = 0; i < list.size(); i++) {
        total += (double) list.get(i).getQuantity() * list.get(i).getBook_price().doubleValue();
    }
    pageContext.setAttribute("total", total);
%>
<table class="table form-inline">
    <%--  <tr>--%>
    <%--    <td>No</td>--%>
    <%--    <td>Title</td>--%>
    <%--    <td>Price</td>--%>
    <%--    <td width="160px">Quantity</td>--%>
    <%--    <td width="80px">Total</td>--%>
    <%--    <td></td>--%>
    <%--  </tr>--%>
    <form style="width: 500px;margin: auto;">
        <div class="row my-4 g-3 align-items-center">
            <div class="col-auto">
                <label for="receiver" class="col-form-label">Receiver</label>
            </div>
            <div class="col-auto">
                <input id="receiver" name="receiver"
                       class="form-control">
            </div>
        </div>

        <div class="row my-4 g-3 align-items-center">
            <div class="col-auto">
                <label for="address" class="col-form-label">Address</label>
            </div>
            <div class="col-auto">
                <input id="address" name="address"
                       class="form-control">
            </div>
        </div>

        <div class="row my-4 g-3 align-items-center">
            <div class="col-auto">
                <label for="phone" class="col-form-label">Phone</label>
            </div>
            <div class="col-auto">
                <input id="phone" name="phone"
                       class="form-control">
            </div>
        </div>

        <div class="row my-4 g-3 align-items-center">
            <div class="col-auto">
                <label for="user_id" class="col-form-label">User</label>
            </div>
            <div class="col-auto">
                <input id="user_id" name="user_id"
                       class="form-control" value="${sessionScope.userVo.username}">
            </div>
        </div>

        <div class="row my-4 g-3 align-items-center">
            <div class="col-auto">
                <label for="price" class="col-form-label">Price</label>
            </div>
            <div class="col-auto">
                <input id="price" name="price"
                       class="form-control" value="${total}">
            </div>
        </div>


        <tr>
            <td>Title</td>
            <td>Price</td>
            <td>Quantity</td>
        </tr>
        <c:forEach var="orderbook" items="${pageScope.list}" varStatus="status">
            <tr>
                <td>${orderbook.book_title}</td>
                <td>${orderbook.book_price}</td>
                <td>${orderbook.quantity}</td>
            </tr>
        </c:forEach>
        <tr><a href="NewOrderServlet" class="btn btn-primary">OK!</a></tr>
    </form>
    <%--  <p style="text-align: right">Total:${total}</p>--%>
</table>
<%@ include file="footer.jsp" %>
</body>
</html>
